// 工作台 密启成
<template>
  <div class="work-bg">
    <!-- 搜索组件 -->
    <Search @searchParent="searchParent" />
    <!-- 内容组件 -->
    <Main
      :workData="workData"
      @parentState="parentState"
      @parentalert="parentalert"
    />
    <!-- 分页组件 -->
    <Page :total="total" :pageSize="pageSize" />
    <!-- 弹框组件（查看病人具体信息） -->
    <Alert :alertdata="alertdata" v-if="isshow" />
  </div>
</template>

<script>
import Search from "./components/search.vue";
import Main from "./components/main.vue";
import Page from "./components/page.vue";
import Alert from "./components/alert.vue";
import { getWorkData, setState, getOneName } from "../../api/workspace";
export default {
  components: {
    Search,
    Main,
    Page,
    Alert,
  },
  data() {
    return {
      workData: [],
      page: 1,
      pageSize: 6,
      total: 0,
      search: "",
      stateId: "",
      isshow: false,
      alertdata: {
        //alertdata.case.ai
        case: "",
      },
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    //获取数据
    getData() {
      const params = {
        search: this.search,
        page: this.page, //页码
        pageSize: this.pageSize, //每页多少条
      };
      getWorkData(params).then((res) => {
        if (res.code == 200) {
          this.workData = res.data;
          this.total = res.total;
        }
      });
    },
    //搜索
    searchParent(val) {
      this.search = val;
      this.getData();
    },
    //接诊 按钮修改
    parentState(val) {
      this.stateId = val;
      this.getData();
      setState(this.stateId).then((res) => {
        if (res.code == 200) {
          this.getData();
        }
      });
    },
    // 控制弹框 + 查看数据
    parentalert(val) {
      this.stateId = val;
      getOneName(this.stateId).then((res) => {
        if (res.code == 200) {
          // 先更新数据   后再更新页面  而后在打开弹框          
          this.alertdata = res.data[0];
          this.getData();
          this.isshow = true;
        }
      });
    },
  },
};
</script>

<style lang='less' scoped>
.work-bg {
  width: 100%;
  min-height: 600px;
  background-color: #fff;
  border-radius: 15px;
  box-shadow: 0px 0px 20px -9px;
}
</style>  